var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  t = require("../../../@babel/runtime/helpers/slicedToArray"),
  n = require("../../../@babel/runtime/helpers/objectSpread2"),
  r = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  i = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  a = require("../../../components/base/m-button/index"),
  o = require("../../../config/index"),
  s = require("../../../utils/index"),
  u = e(require("../behavior")),
  d = s.helper.publish;

function c(e) {
  return l.apply(this, arguments)
}

function l() {
  return (l = i(r().mark((function e(n) {
    var i, a, o, s, u, c, l, p, f, m, h, b, v, g;
    return r().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          return i = this.data.mode, e.next = 3, $.request["GET/business/recruit/worker/detail/" + this.data.uu_id]();
        case 3:
          a = e.sent, o = t(a, 1), 20002 === (s = o[0]).code ? (u = s.data,
            c = u.phone, l = u.description, p = u.class_id, f = u.place, m = u.provinceId, h = u.cityId, b = u.latitude, v = u.longitude, g = {
              address: f,
              city_id: h,
              city_text: u.cityText,
              latitude: b,
              longitude: v,
              province_id: m,
              province_text: u.provinceText
            },this.selectComponent("#form").setValues({
              address: g,
              phone: c,
              detail: l,
              type: [{
                id: u.driverTypeId,
                name: u.driverTypeName
              }]
            })) : 14004 == s.code ? $.jxAlert({
            mode: "confirm",
            hideClose: !0,
            title: "温馨提示",
            content: s.msg,
            confirmText: "刷新信息"
          }).then((function () {
            d.reqInfoRefresh({
              mode: i,
              info: n
            }, !0)
          })).catch((function () {
            $.router.back()
          })) : $.jxAlert({
            content: s.msg
          });
        case 7:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))).apply(this, arguments)
}
Page({
  useStore: function (e) {
    return {
      userInfo: e.storage.userInfo,
      machineConfig: e.global.machineConfig
    }
  },
  behaviors: [u.default],
  data: {
    mode: o.typeMode.recruit
  },
  onLoad: function (e) {
    var t = this;
    return i(r().mark((function n() {
      var i;
      return r().wrap((function (n) {
        switch (n.prev = n.next) {
          case 0:
            t.selectComponent("#form").setValues({
              tel: wx.getStorageSync('userPhone')
            }), (i = e.uu_id) && (t.setData({
              uu_id: i
            }), c.call(t, i));
          case 3:
          case "end":
            return n.stop()
        }
      }), n)
    })))()
  },
  onSubmit: (0, a.apply)(i(r().mark((function e() {
    var t, i, a, o, s, u, c, l, p, f, m, h, b;
    return r().wrap((function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return e.next = 5, this.selectComponent("#form").verify({
            address: [{
              required: !0,
              message: "请选择工作地点"
            }],
            tel: [{
              required: !0,
              message: "请输入电话"
            }],
            type: [{
              required: !0,
              message: "请选择工种"
            }]
          });
        case 2:
          if (a = e.sent, !this.data.isShowCode || a.code) {
            e.next = 5;
            break
          }
          return e.abrupt("return", void $.msg("请输入验证码"));
        case 5:
          if (a = e.sent, a.detail && !((null === (t = a.detail) || void 0 === t ? void 0 : t.length) < 5)) {
            e.next = 7;
            break
          }
          return e.abrupt("return", void $.msg("招工详情必须大于5个字符"));
        case 7:
          if (o = a.address, s = a.type, u = this.data, c = u.userInfo, l = u.machineConfig, p = u.uu_id, f = u.mode, m = n(n({
              mode: f,
              user_name: c.name
            }, o), {}, {
              class_id: (null == s || null === (i = s.map((function (e) {
                return e.id
              }))) || void 0 === i ? void 0 : i.join(",")) || "",
              modelId: (null == s || null === (i = s.map((function (e) {
                return e.id
              }))) || void 0 === i ? void 0 : i.join(",")) || "",
              modelName: (null == s || null === (i = s.map((function (e) {
                return e.name
              }))) || void 0 === i ? void 0 : i.join(",")) || "",
              phone: a.tel || "",
              description: a.detail || "",
              place: o.address,
              provinceId: o.province_id,
              provinceText: o.province_text,
              cityId: o.city_id,
              cityText: o.city_text,
            }), !p) {
            e.next = 13;
            break
          }
          b = {
            mode: f,
            user: c.name,
            modelId: (null == s || null === (i = s.map((function (e) {
              return e.id
            }))) || void 0 === i ? void 0 : i.join(",")) || "",
            modelName: (null == s || null === (i = s.map((function (e) {
              return e.name
            }))) || void 0 === i ? void 0 : i.join(",")) || "",
            phon: a.tel || "",
            capt: a.code || "",
            desc: a.detail || "",
            title: a.detail || "",
            type: (null == s || null === (h = s.map((function (e) {
              return e.id
            }))) || void 0 === h ? void 0 : h.join(",")) || "",
            longitude: o.longitude,
            latitude: o.latitude,
            place: o.address,
            id: p
          }, d.sendMachineInfo(m, p), e.next = 15;
          break;
        case 13:
          return e.next = 15, d.checkPayReleasePopup(f, (function (e) {
            e ? (m.pay_code = "10001", m.coin = l.push_consume_coin, d.sendMachineInfo(m)) : d.sendMachineInfo(m)
          }));
        case 15:
        case "end":
          return e.stop()
      }
    }), e, this)
  }))))
});